home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utilsys / rss14gmd.lha / RSys_1.4gmd / Asm / RSysIdents.asm < prev    next >
Assembly Source File  |  1996-04-08  |  8KB  |  354 lines

  1. ;======================================================================
  2. ;
  3. ;    SetCPU V1.60
  4. ;    by Dave Haynie, April 13, 1990
  5. ;    Released to the Public Domain
  6. ;
  7. ;    IDENTS.A MODULE
  8. ;
  9. ;    This module contains the functions that ID the CPU, MMU, and FPU
  10. ;    type indtalled in the system.
  11. ;
  12. ;======================================================================
  13.  
  14. ;    include "setcpu.i"
  15.  
  16. ;    INCLUDE "include:exec/types.i"
  17. ;    INCLUDE "include:exec/execbase.i"
  18. ;    include "include:exec/tasks.i"
  19.  
  20.     INCLUDE "exec/types.i"
  21.     INCLUDE "exec/execbase.i"
  22.     INCLUDE "exec/tasks.i"
  23.  
  24. CALLSYS        macro   *
  25.         jsr     LVO\1(A6)
  26.         endm
  27.  
  28. MOVEC_        macro    *
  29.         ifc '\1','cacr'
  30.             ifc '\2','d0'
  31.             dc.w    $4e7a    ; MOVEC    cacr,d0
  32.             dc.w    $0002
  33.             mexit
  34.             endc
  35.             ifc '\2','d1'
  36.             dc.w    $4e7a    ; MOVEC    cacr,d1
  37.             dc.w    $1002
  38.             mexit
  39.             endc
  40.         endc
  41.         ifc '\2','cacr'
  42.             ifc '\1','d0'
  43.             dc.w    $4e7b    ; MOVEC d0,cacr
  44.             dc.w    $0002
  45.             mexit
  46.             endc
  47.             ifc '\1','d1'
  48.             dc.w    $4e7b    ; MOVEC d1,cacr
  49.             dc.w    $1002
  50.             mexit
  51.             endc
  52.         endc
  53.         ifc '\1','vbr'
  54.             ifc '\2','d0'
  55.             dc.w    $4e7a    ; MOVEC    vbr,d0
  56.             dc.w    $0801
  57.             mexit
  58.             endc
  59.         endm
  60.  
  61. PMOVE_        macro    *
  62.         ifc '\1','tc'
  63.             ifc '\2','(sp)'
  64.             dc.w    $f017    ; PMOVE tc,(sp)
  65.             dc.w    $4200
  66.             mexit
  67.             endc
  68.             ifc '\2','(a0)'
  69.             dc.w    $f010    ; PMOVE tc,(a0)
  70.             dc.w    $4200
  71.             mexit
  72.             endc
  73.         endc
  74.         ifc '\1','crp'
  75.             ifc '\2','(a0)'
  76.             dc.w    $f010    ; PMOVE    crp,(a0)
  77.             dc.w    $4e00
  78.             mexit
  79.             endc
  80.         endc
  81.         ifc '\1','(a0)'
  82.             ifc '\2','crp'
  83.             dc.w    $f010    ; PMOVE    (a0),crp
  84.             dc.w    $4c00
  85.             mexit
  86.             endc
  87.             ifc '\2','tc'
  88.             dc.w    $f010    ; PMOVE (a0),tc
  89.             dc.w    $4000
  90.             mexit
  91.             endc
  92.         endc
  93.         ifc '\1','(a1)'
  94.             ifc '\2','crp'
  95.             dc.w    $f011    ; PMOVE (a1),crp
  96.             dc.w    $4c00
  97.             mexit
  98.             endc
  99.         endc
  100.         endm
  101.  
  102. CIB_ENABLE    EQU    0
  103. CIB_FREEZE    EQU    1
  104. CIB_ENTRY    EQU    2
  105. CIB_CLEAR    EQU    3
  106. CIB_BURST    EQU    4
  107.  
  108. CDB_ENABLE    EQU    8
  109. CDB_FREEZE    EQU    9
  110. CDB_ENTRY    EQU    10
  111. CDB_CLEAR    EQU    11
  112. CDB_BURST    EQU    12
  113. CDB_WALLOC    EQU    13
  114.  
  115. CIB_ENABLE40    EQU    15
  116. CDB_ENABLE40    EQU    31
  117.  
  118. ;AFB_68030    EQU    2
  119. ;AFB_68040    EQU    3
  120. ;AFB_68882    EQU    5
  121.  
  122. ATNFLGS        EQU    $129
  123.  
  124. LVOSupervisor    EQU    -30
  125. LVOSuperState    EQU    -150
  126. LVOFindTask    EQU    -294
  127. LVOAllocTrap    EQU    -342
  128. LVOFreeTrap    EQU    -348
  129. LVOCacheClearU    EQU    -636
  130. LVOCacheControl    EQU    -648
  131.  
  132. ANYCREG        EQU    $00dff010
  133.  
  134. ;GMD    machine mc68020
  135. ;GMD        mc68881
  136.  
  137.  
  138. ;GMD     cseg
  139.  
  140. ;GMD    CSECT __MERGED
  141.     CSECT __GZZ
  142.  
  143.     xdef    _GetCPUType    ; ID the CPU
  144.     xdef    _GetMMUType    ; ID the MMU
  145.     xdef    _GetFPUType    ; ID the FPU
  146.  
  147. ;======================================================================
  148. ;
  149. ;    This routine checks CPU flags early in ExecBase for extended
  150. ;    CPUs that test as a 68020 under 1.3.  If these flags are set,
  151. ;    the actual CPU/MMU type test can be skipped.
  152. ;
  153. ;======================================================================
  154.  
  155. TestFlags:
  156.     moveq.l    #0,d0
  157.     btst.b    #AFB_68040,ATNFLGS(a6)    ; Does the OS think an '040 is here?
  158.     beq NoEarly40
  159.     move.l    #68040,d0
  160.     rts
  161. NoEarly40:
  162.     btst.b    #AFB_68030,ATNFLGS(a6)    ; Does the OS think an '030 is here?
  163.     beq    NoEarly30
  164.     move.l    #68030,d0        ; Sure does...
  165. NoEarly30:
  166.     rts
  167.  
  168.  
  169. ;======================================================================
  170. ;
  171. ;    This function returns the type of the CPU in the system as a
  172. ;    longword: 68000, 68010, 68020, or 68030.  The testing must be done
  173. ;    in reverse order, in that any higher CPU also has the bits set for
  174. ;    a lower CPU.  Also, since 1.3 doesn't recognize the 68030, if I
  175. ;    find the 68020 bit set, I always check for the presence of a
  176. ;    68030.
  177. ;
  178. ;    This routine should be the first test routine called under 1.2
  179. ;    and 1.3.
  180. ;
  181. ;    ULONG GetCPUType();
  182. ;
  183. ;======================================================================
  184.  
  185. _GetCPUType:
  186.     move.l    4,a6            ; Get ExecBase
  187.     jsr    TestFlags        ; Check extended CPU types
  188.     cmp.l    #0,d0
  189.     beq    CPURealTest
  190.     rts
  191. CPURealTest:
  192.     movem.l    a4/a5,-(sp)        ; Save this register
  193.     btst.b    #AFB_68020,ATNFLGS(a6)    ; Maybe a 68020
  194.     bne    FindReal32
  195.     btst.b    #AFB_68010,ATNFLGS(a6)    ; Maybe a 68010?
  196.     bne    Found10
  197.     move.l    #68000,d0        ; Just a measley '000
  198.     movem.l    (sp)+,a4/a5
  199.     rts
  200. Found10:
  201.     move.l    #68010,d0        ; Yup, we're an '010
  202.     movem.l    (sp)+,a4/a5
  203.     rts
  204. FindReal32:
  205.     move.w    LIB_VERSION(a6),d0    ; Are we in 2.0?
  206.     cmp.w    #36,d0            ; If so, we don't need to test
  207.     bge    No40
  208.  
  209.     lea.l    SuperGCT,a5        ; Get the start of the supervisor code
  210.     CALLSYS    Supervisor
  211.  
  212.     btst.l    #CIB_BURST,d0        ; Do we have a set burst bit?
  213.     beq    No30
  214.     move.l    #68030,d0        ; It's a 68030
  215.     bset.b    #AFB_68030,ATNFLGS(a6)
  216.     movem.l    (sp)+,a4/a5
  217.     rts
  218. No30:    
  219.     btst.l    #CIB_ENABLE40,d1    ; Do we have 040 cache enable?
  220.     beq    No40
  221.     move.l    #68040,d0        ; It's a 68040
  222.     bset.b    #AFB_68040,ATNFLGS(a6)
  223.     movem.l    (sp)+,a4/a5
  224.     rts
  225. No40:
  226.     move.l    #68020,d0        ; Guess we're a plain old '020
  227.     movem.l    (sp)+,a4/a5
  228.     rts
  229.  
  230.     ; This routine tries to set a few interesting CACR bits, and
  231.     ; returns the actual register value that took in d0.
  232. SuperGCT:
  233.     MOVEC_    cacr,d1            ; Get the cache register
  234.     move.l    d1,d0            ; Make a copy
  235.     bset.l    #CIB_BURST,d0        ; Set the inst burst bit 030
  236.     bclr.l    #CIB_ENABLE,d0        ; Clear the inst cache bit 030
  237.     bset.l    #CIB_ENABLE40,d0    ; Set the inst cache bit 040
  238.     MOVEC_    d0,cacr            ; Try to set the CACR
  239.     MOVEC_    cacr,d0            ; Save the real value
  240.     MOVEC_    d1,cacr            ; Restore it
  241.     rte
  242.  
  243. ;======================================================================
  244. ;
  245. ;    This function returns 0L if the system contains no MMU, 
  246. ;    68851L if the system does contain an 68851, or the CPU number
  247. ;    for CPUs with integral CPUs.
  248. ;
  249. ;    This routine seems to lock up on at least some CSA 68020 
  250. ;    boards, though it runs just fine on those from Ronin and 
  251. ;    Commodore, as well as all 68030 boards it's been tested on.
  252. ;
  253. ;    ULONG GetMMUType()
  254. ;
  255. ;======================================================================
  256.  
  257. _GetMMUType:
  258.     move.l    4,a6            ; Get ExecBase
  259.     jsr    TestFlags        ; Check extended CPU types
  260.     cmp.l    #0,d0
  261.     beq    MMURealTest
  262.     rts
  263.  
  264.     ; For any other machine, a real test must be done.  The test will
  265.     ; try an MMU instruction.  The instruction will fail unless we're
  266.     ; on a "bogus MMU" system, where the FPU responds as an MMU.
  267. MMURealTest:
  268.     movem.l    a3/a4/a5,-(sp)        ; Save this stuff
  269.     move.l    #0,a1    
  270.     CALLSYS    FindTask        ; Call FindTask(0L)
  271.     move.l    d0,a3
  272.  
  273.     move.l    TC_TRAPCODE(a3),a4    ; Change the exception vector
  274.     move.l    #MMUTraps,TC_TRAPCODE(a3)
  275.     
  276.     move.l    #-1,d0            ; Try to detect undecode FPU
  277.     subq.l    #4,sp            ; Get a local variable
  278.     PMOVE_    tc,(sp)            ; Let's try an MMU instruction
  279.     addq.l    #4,sp            ; Return that local
  280.     move.l    a4,TC_TRAPCODE(a3)    ; Reset exception stuff
  281.     movem.l    (sp)+,a3/a4/a5        ; and return the registers
  282.     rts
  283.  
  284.     ; This is the exception code.  No matter what machine we're on,
  285.     ; we get an exception.  If the MMU's in place, we should get a
  286.     ; privilige violation; if not, an F-Line emulation exception.
  287. MMUTraps:
  288.     move.l    (sp)+,d0        ; Get Amiga supplied exception #
  289.     cmpi    #11,d0            ; Is it an F-Line?
  290.     beq    MMUNope            ; If so, go to the fail routine
  291.     move.l    #68851,d0        ; We have MMU
  292.     addq.l    #4,2(sp)        ; Skip the MMU instruction
  293.     rte
  294. MMUNope:
  295.     moveq.l    #0,d0            ; It dinna woik,
  296.     addq.l    #4,2(sp)        ; Skip the MMU instruction
  297.     rte
  298.  
  299. ;======================================================================
  300. ;
  301. ;    This function returns the type of the FPU in the system as a
  302. ;    longword: 0 (no FPU), 68881, or 68882.
  303. ;
  304. ;    ULONG GetFPUType();
  305. ;
  306. ;======================================================================
  307.  
  308. _GetFPUType:
  309.     move.l    4,a6            ; Get ExecBase
  310.     btst.b    #AFB_68040,ATNFLGS(a6)    ; Is there a 68040 here?
  311.     beq    Look4FPU
  312.     move.l    #68040,d0
  313.     rts
  314. Look4FPU:    
  315.     move.l    a5,-(sp)        ; Save this register
  316.     btst.b    #AFB_68881,ATNFLGS(a6)    ; Does the OS think an FPU is here?
  317.     bne    FPUHere
  318.     moveq.l    #0,d0            ; No FPU here, dude
  319.     move.l    (sp)+,a5        ; Give back the register
  320.     rts
  321. FPUHere:
  322.     btst.b    #AFB_68882,ATNFLGS(a6)    ; How's about an '882?
  323.     beq    FPUTest
  324.     move.l    #68882,d0        ; Sure does...
  325.     move.l    (sp)+,a5
  326.     rts
  327. FPUTest:
  328.     move.w    LIB_VERSION(a6),d0    ; Are we in 2.0?
  329.     cmp.w    #36,d0            ; If so, we don't need to test
  330.     blt    FPUTrap
  331.     move.l    #68881,d0
  332.     move.l    (sp)+,a5
  333.     rts
  334. FPUTrap:
  335.     lea.l    FPUSuper,a5        ; Get the start of the supervisor code
  336.     CALLSYS    Supervisor
  337.     move.l    (sp)+,a5        ; Give back registers
  338.     rts
  339. FPUSuper:
  340.     move.l    #68881,d0        ; Assume we're a 68881
  341.     fsave    -(sp)            ; Test and check
  342.     moveq.l    #0,d1
  343.     move.b    1(sp),d1        ; Size of this frame
  344.     cmpi    #$18,d1
  345.     beq FPU81
  346.     move.l    #68882,d0        ; It's a 68882
  347.     bset.b    #AFB_68882,ATNFLGS(a6)
  348. FPU81:
  349.     frestore (sp)+            ; Restore the stack
  350.     rte
  351.  
  352.     end
  353.  
  354.